import 'package:backend.core/core/domain/entities/google_play/google_play_transaction_revocation_info.dart';
import 'package:backend.purchases/domain/entities/google_play_api/google_play_api_revoked_purchased_item.dart';
import 'package:backend.purchases/domain/helpers/google_play/create_google_play_transaction_revocation_reason_from_api_one.dart';
import 'package:backend.purchases/domain/helpers/google_play/create_google_play_transaction_revocation_source_from_api_one.dart';

abstract class CreateGooglePlayTransactionRevocationInfoFromApiRevokedPurchasedItem {
  GooglePlayTransactionRevocationInfo call({
    required GooglePlayApiRevokedPurchasedItem revokedPurchasedItem,
  });
}

class CreateGooglePlayTransactionRevocationInfoFromApiRevokedPurchasedItemImpl
    implements CreateGooglePlayTransactionRevocationInfoFromApiRevokedPurchasedItem {
  const CreateGooglePlayTransactionRevocationInfoFromApiRevokedPurchasedItemImpl({
    required CreateGooglePlayTransactionRevocationSourceFromApiOne
        createGooglePlayTransactionRevocationSourceFromApiOne,
    required CreateGooglePlayTransactionRevocationReasonFromApiOne
        createGooglePlayTransactionRevocationReasonFromApiOne,
  })  : _createGooglePlayTransactionRevocationSourceFromApiOne =
            createGooglePlayTransactionRevocationSourceFromApiOne,
        _createGooglePlayTransactionRevocationReasonFromApiOne =
            createGooglePlayTransactionRevocationReasonFromApiOne;

  final CreateGooglePlayTransactionRevocationSourceFromApiOne
      _createGooglePlayTransactionRevocationSourceFromApiOne;
  final CreateGooglePlayTransactionRevocationReasonFromApiOne
      _createGooglePlayTransactionRevocationReasonFromApiOne;

  @override
  GooglePlayTransactionRevocationInfo call({
    required GooglePlayApiRevokedPurchasedItem revokedPurchasedItem,
  }) {
    final source = _createGooglePlayTransactionRevocationSourceFromApiOne(
      apiRevocationSource: revokedPurchasedItem.revocationSource,
    );

    final reason = _createGooglePlayTransactionRevocationReasonFromApiOne(
      apiRevocationReason: revokedPurchasedItem.revocationReason,
    );

    return GooglePlayTransactionRevocationInfo(
      source: source,
      reason: reason,
      time: revokedPurchasedItem.revocationTime,
    );
  }
}
